package com.servlet.filter;

import cn.hutool.extra.servlet.ServletUtil;
import com.servlet.bean.User;
import com.servlet.utils.ResponseVo;
import com.servlet.utils.ServletUtils;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @Title: BAuthFilter
 * @Description:
 * @Auther: py
 * @Version: 1.0
 * @create 2023/12/27 11:01
 */
@WebFilter("/*")
public class BAuthFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest)servletRequest;
        HttpServletResponse response = (HttpServletResponse)servletResponse;
        filterChain.doFilter(request,response);
//        String method = request.getParameter("method");
//        // 判断method 是否是登录和注册 登录注册 直接放行
//        if(method.equals("register") || method.equals("login") ) {
//            filterChain.doFilter(request,response);
//            return;
//        }
//        // 判断当前用户是否有登录
//        HttpSession session = request.getSession();
//        User user =(User)  session.getAttribute("user");
//        if(user != null) {
//            filterChain.doFilter(request,response);
//            return;
//        }
//
//        ServletUtils.writeResponse(response, ResponseVo.error("当前没有登录！"));



    }

    @Override
    public void destroy() {

    }
}
